package com.ruoyi.system.Controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CmManagerRole;
import com.ruoyi.system.service.ICmManagerRoleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社管角色管理Controller
 * 
 * @author pop404NotFound
 * @date 2021-11-25
 */
@Controller
@RequestMapping("/CmSystem/managerrole")
public class CmManagerRoleController extends BaseController
{
    private String prefix = "CmSystem/managerrole";

    @Autowired
    private ICmManagerRoleService cmManagerRoleService;

    @RequiresPermissions("CmSystem:managerrole:view")
    @GetMapping()
    public String managerrole()
    {
        return prefix + "/managerrole";
    }

    /**
     * 查询社管角色管理列表
     */
    @RequiresPermissions("CmSystem:managerrole:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmManagerRole cmManagerRole)
    {
        startPage();
        List<CmManagerRole> list = cmManagerRoleService.selectCmManagerRoleList(cmManagerRole);
        return getDataTable(list);
    }

    /**
     * 导出社管角色管理列表
     */
    @RequiresPermissions("CmSystem:managerrole:export")
    @Log(title = "社管角色管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmManagerRole cmManagerRole)
    {
        List<CmManagerRole> list = cmManagerRoleService.selectCmManagerRoleList(cmManagerRole);
        ExcelUtil<CmManagerRole> util = new ExcelUtil<CmManagerRole>(CmManagerRole.class);
        return util.exportExcel(list, "社管角色管理数据");
    }

    /**
     * 新增社管角色管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社管角色管理
     */
    @RequiresPermissions("CmSystem:managerrole:add")
    @Log(title = "社管角色管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmManagerRole cmManagerRole)
    {
        return toAjax(cmManagerRoleService.insertCmManagerRole(cmManagerRole));
    }

    /**
     * 修改社管角色管理
     */
    @GetMapping("/edit/{roleId}")
    public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap)
    {
        CmManagerRole cmManagerRole = cmManagerRoleService.selectCmManagerRoleByRoleId(roleId);
        mmap.put("cmManagerRole", cmManagerRole);
        return prefix + "/edit";
    }

    /**
     * 修改保存社管角色管理
     */
    @RequiresPermissions("CmSystem:managerrole:edit")
    @Log(title = "社管角色管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmManagerRole cmManagerRole)
    {
        return toAjax(cmManagerRoleService.updateCmManagerRole(cmManagerRole));
    }

    /**
     * 删除社管角色管理
     */
    @RequiresPermissions("CmSystem:managerrole:remove")
    @Log(title = "社管角色管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmManagerRoleService.deleteCmManagerRoleByRoleIds(ids));
    }
}
